﻿Public Class FormCategoryEditor

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Dim typeId = Me.cboTypeName.SelectedValue
        If txtCategoryId.Enabled Then
            Cmd.ExecuteNonQuery("INSERT INTO Category VALUES(N'" & txtCategoryName.Text & "'," & typeId & ",1)")
        Else
            Cmd.ExecuteNonQuery("UPDATE Category SET CategoryName=N'" & txtCategoryName.Text & "',TypeId=" & typeId & " WHERE CategoryId=" & txtCategoryId.Text & "")
        End If

        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dim dt As DataTable = Cmd.ExecuteDataTable("SELECT * FROM Type WHERE Active=1")
        Me.cboTypeName.DataSource = dt
        Me.cboTypeName.DisplayMember = "TypeName"
        Me.cboTypeName.ValueMember = "TypeId"
    End Sub

    Private Sub FormCategoryEditor_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class